const mysql = require('mysql')
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: 'qqq123',
  port: '3306',
  database: 'test'
})
connection.connect(); // 建立连接
const sql = "insert into stu(name,age,sex) values(?,?,?)" //SQL语句
const sqlParams = ["小明4", 22, 1] // 动态参数
connection.query(sql, sqlParams, (err, result) => {
  if (err) {
    console.log(err);
    return
  }
  console.log(result); // 打印添加结果
})
connection.end() // 关闭连接